<template>
  <div class="header-bar">
    <div class="top">
      <div class="title">{{title}}</div>
      <div class="toolbar">
        <div class="label">{{label}}</div>
        <select class="custom-select" v-if="month" v-model="currentMonth">
          <option v-for="item in months" :key="item" :value="item">{{item}}</option>
        </select>
        <select class="custom-select" v-else>
          <option value="2017">2017</option>
        </select>
      </div>
    </div>
    <div class="bottom" v-if="showBottom">
      <div class="title">BBAC Plant</div>
      <div class="toolbar">
        <div class="legend">
          <div class="rect success"></div>
          Worse than target
        </div>
        <div class="legend">
          <div class="rect danger"></div>
          Better than target
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: 'header-bar',
  components: {

  },
  props: {
    title: String,
    label: String,
    month: String,
    showBottom: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      currentMonth: null,
      months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    }
  },
  watch: {
    '$route.query.month': {
      handler: function (key) {
        this.currentMonth = key
      },
      immediate: true
    }
  }
}
</script>
<style lang="scss" scoped>
@import '../style';

.header-bar {
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
    border-bottom: 1px solid #BCC7D3;

    .title {
      @extend %title;
    }
    .toolbar {
      display: flex;
      .label {
        line-height: 30px;
        margin-right: 10px;
      }
      .custom-select {
        height: 30px;
        border-radius: 15px;
        border-width: 0;
        width: 60px;
        background-color: rgb(215, 221, 228);
        font-size: 12px;
        padding-left: 8px;
      }
    }
  }

  .bottom {
    @extend %flex-lr;
    .title {
      @extend %title;
    }
    .toolbar {
      display: flex;
      line-height: 30px;
      .legend {
        display: flex;
        align-items: center;
        margin-left: 50px;
        .rect {
          display: inline-block;
          width: 20px;
          height: 20px;
          margin-right: 8px;
          &.success {
            background-color: #50D372;
          }
          &.danger {
            background-color: #E5353A;
          }
        }
      }
    }
  }
}
</style>
